-- Dakara weapon variables
DakaraWeapon = {}

-- Dakara weapon states
DakaraWeapon.States = {}
DakaraWeapon.States.IDLE = 1
DakaraWeapon.States.CHARGING = 2
DakaraWeapon.States.FIRING = 3
DakaraWeapon.state = DakaraWeapon.States.IDLE

-- Dakara weapon 
DakaraWeapon.Targets = { "player", "npc" }
DakaraWeapon.energyCharged = 0
DakaraWeapon.safeZoneRadius = 500

-- Dakara weapon constants
-- You can edit these to modify the behaviour of the weapon
DakaraWeapon.ENERGY_PER_SHOT = StarGate.CFG:Get("zpm", "capacity", 10000000) -- Energy required to fire
DakaraWeapon.CHARGE_TIME = 20 -- Number of seconds that the weapon takes to charge before firing
DakaraWeapon.EFFECT_DURATION = 10 -- Duration of the charging effect (in seconds)
DakaraWeapon.IS_SHIELD_PIERCING = false -- Does the weapon ignore shields?
DakaraWeapon.ARE_CONSTRAINED_ENTS_PROTECTED = false -- Are entities that are constrained (welded, etc.) to the weapon immune from disintegration?
DakaraWeapon.DEFAULT_MODEL = "models/props_combine/breenglobe.mdl"
DakaraWeapon.MAX_HEALTH = 100
DakaraWeapon.MAX_ARMOUR = 75

-- Dakara wave
DakaraWeapon.Wave = {}
DakaraWeapon.Wave.MAX_RADIUS = 8000
DakaraWeapon.Wave.EXPANSION_RATE = 50

-- Dakara sound effects
DakaraWeapon.Sounds = {}
DakaraWeapon.Sounds.Paths = {}
DakaraWeapon.Sounds.Paths["charging"] = Sound("StargateExtras/dakara_charging.wav")
DakaraWeapon.Sounds.Paths["firing"] = Sound("StargateExtras/dakara_firing.wav")

if(SERVER) then
   resource.AddFile(DakaraWeapon.Sounds.Paths["charging"])
   resource.AddFile(DakaraWeapon.Sounds.Paths["firing"])
end

-- Dakara animations
DakaraWeapon.Anims = {}
DakaraWeapon.Anims[DakaraWeapon.States.IDLE] = "idle"
DakaraWeapon.Anims[DakaraWeapon.States.CHARGING] = "charging"
DakaraWeapon.Anims[DakaraWeapon.States.FIRING] = "firing"

function DakaraWeapon:Create(targets, safeZoneRadius)
   local weapon = table.Copy(self)
   setmetatable(weapon, self)
   
   weapon:Setup(targets, safeZoneRadius)
   
   return weapon
end

function DakaraWeapon:Setup(targets, safeZoneRadius)
   if(self.state ~= self.States.IDLE) then
      return false
   end
   
   self.Targets = targets
   self.safeZoneRadius = safeZoneRadius
   
   return true
end

function DakaraWeapon:IsCharged()
   return self.energyCharged >= self.ENERGY_PER_SHOT
end
